﻿

#pragma once


#if FUEL_OS_WINDOWS
FINLINE bool FInputTransmit_windows(FINPUT_PACKAGE& ipk, UINT msg, WPARAM wparam, LPARAM lparam)
{
    ipk.nType = eIT_UNKNOWN;
    ipk.p1.t = eFDT_unknown;
    ipk.p2.t = eFDT_unknown;
    switch (msg)
    {
    case WM_LBUTTONDOWN:
        ipk.nType = eIT_LBUTTON_DOWN;
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;
    case WM_LBUTTONUP:
        ipk.nType = eIT_LBUTTON_UP;
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;
    case WM_LBUTTONDBLCLK:
        ipk.nType = eIT_LBUTTON_DBCLICK;
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;

    case WM_MBUTTONDOWN:
        ipk.nType = eIT_MBUTTON_DOWN;
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;
    case WM_MBUTTONUP:
        ipk.nType = eIT_MBUTTON_UP;
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;
    case WM_MBUTTONDBLCLK:
        ipk.nType = eIT_MBUTTON_DBCLICK;
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;

    case WM_RBUTTONDOWN:
        ipk.nType = eIT_RBUTTON_DOWN;
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;
    case WM_RBUTTONUP:
        ipk.nType = eIT_RBUTTON_UP;
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;
    case WM_RBUTTONDBLCLK:
        ipk.nType = eIT_RBUTTON_DBCLICK;
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;

    case WM_MOUSEMOVE:
        ipk.nType = eIT_MOUSEMOVE;
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;
    case WM_MOUSEWHEEL:
        ipk.nType = eIT_MOUSEWHEEL;
        ipk.p1 = (F_GET_WHEEL_DELTA(wparam) > 0 ? true : false);
        ipk.p2 = FDT_VECTOR2_CREATE(F_GET_XF(lparam), F_GET_YF(lparam));
        return true;

    case WM_KEYDOWN:
        ipk.nType = eIT_KEYDOWN;
        ipk.p1 = (UINT)wparam;
        return true;
    case WM_KEYUP:
        ipk.nType = eIT_KEYUP;
        ipk.p1 = (UINT)wparam;
        return true;
    case WM_CHAR:
        ipk.nType = eIT_CHAR;
        ipk.p1 = (UINT)wparam;
        return true;

    case WM_ACTIVATE:
        ipk.nType = eIT_ACTIVATE;
        ipk.p1 = (((BYTE)wparam != WA_INACTIVE) ? true : false);
        return true;
    case WM_SETCURSOR:
        ipk.nType = eIT_SETCURSOR;
        return true;
    }
    return false;
}
#elif FUEL_OS_ANDROID
FINLINE bool FInputTransmit_android_motion_make(FINPUT_PACKAGE& ipk, int type, float x, float y)
{
    switch (type)
    {
    case AMOTION_EVENT_ACTION_DOWN:
        ipk.nType = eIT_LBUTTON_DOWN;
        ipk.p2 = FDT_VECTOR2_CREATE(x, y);
        break;
    case AMOTION_EVENT_ACTION_UP:
        ipk.nType = eIT_LBUTTON_UP;
        ipk.p2 = FDT_VECTOR2_CREATE(x, y);
        break;
    case AMOTION_EVENT_ACTION_MOVE:
        ipk.nType = eIT_MOUSEMOVE;
        ipk.p2 = FDT_VECTOR2_CREATE(x, y);
        break;
    default:
        return false;
    }
    return true;
}
FINLINE bool FInputTransmit_android_motion(FINPUT_PACKAGE& ipk, struct android_app* app, AInputEvent* event, float& ox, float& oy)
{
    ipk.nType = eIT_UNKNOWN;
    ipk.p1.t = eFDT_unknown;
    ipk.p2.t = eFDT_unknown;

    ox = AMotionEvent_getX(event, 0);
    oy = AMotionEvent_getY(event, 0);

    return FInputTransmit_android_motion_make(ipk, AMotionEvent_getAction(event), ox, oy);
}
FINLINE bool FInputTransmit_android_key_make(FINPUT_PACKAGE& ipk, int type, int key)
{
    switch (type)
    {
    case AKEY_EVENT_ACTION_DOWN:
        ipk.nType = eIT_KEYDOWN;
        break;
    case AKEY_EVENT_ACTION_UP:
        ipk.nType = eIT_KEYUP;
        break;
    default:
        return false;
    }

    switch (key)
    {
    case AKEYCODE_0:
    case AKEYCODE_1:
    case AKEYCODE_2:
    case AKEYCODE_3:
    case AKEYCODE_4:
    case AKEYCODE_5:
    case AKEYCODE_6:
    case AKEYCODE_7:
    case AKEYCODE_8:
    case AKEYCODE_9:
        ipk.p1 = (UINT)(key - AKEYCODE_0 + '0');
        break;
    case AKEYCODE_A:
    case AKEYCODE_B:
    case AKEYCODE_C:
    case AKEYCODE_D:
    case AKEYCODE_E:
    case AKEYCODE_F:
    case AKEYCODE_G:
    case AKEYCODE_H:
    case AKEYCODE_I:
    case AKEYCODE_J:
    case AKEYCODE_K:
    case AKEYCODE_L:
    case AKEYCODE_M:
    case AKEYCODE_N:
    case AKEYCODE_O:
    case AKEYCODE_P:
    case AKEYCODE_Q:
    case AKEYCODE_R:
    case AKEYCODE_S:
    case AKEYCODE_T:
    case AKEYCODE_U:
    case AKEYCODE_V:
    case AKEYCODE_W:
    case AKEYCODE_X:
    case AKEYCODE_Y:
    case AKEYCODE_Z:
        ipk.p1 = (UINT)(key - AKEYCODE_A + 'A');
        break;

    case AKEYCODE_ENTER:  ipk.p1 = (UINT)VK_RETURN; break;
    case AKEYCODE_DEL: 	  ipk.p1 = (UINT)VK_BACK;   break;
    case AKEYCODE_SPACE:  ipk.p1 = (UINT)VK_SPACE;  break;

    case AKEYCODE_HOME:        ipk.p1 = (UINT)VK_MB_HOME;       break;
    case AKEYCODE_MENU:        ipk.p1 = (UINT)VK_MB_MENU;       break;
    case AKEYCODE_BACK:        ipk.p1 = (UINT)VK_MB_BACK;       break;
    case AKEYCODE_POWER:       ipk.p1 = (UINT)VK_MB_POWER;      break;
    case AKEYCODE_VOLUME_UP:   ipk.p1 = (UINT)VK_MB_VOLUME_UP;  break;
    case AKEYCODE_VOLUME_DOWN: ipk.p1 = (UINT)VK_MB_VOLUME_DOWN;break;
    case AKEYCODE_MUTE:        ipk.p1 = (UINT)VK_MB_MUTE;       break;

    case AKEYCODE_DPAD_CENTER: ipk.p1 = (UINT)VK_MB_PAD_CENTER; break;
    case AKEYCODE_DPAD_UP:     ipk.p1 = (UINT)VK_MB_PAD_UP;     break;
    case AKEYCODE_DPAD_DOWN:   ipk.p1 = (UINT)VK_MB_PAD_DOWN;   break;
    case AKEYCODE_DPAD_LEFT:   ipk.p1 = (UINT)VK_MB_PAD_LEFT;   break;
    case AKEYCODE_DPAD_RIGHT:  ipk.p1 = (UINT)VK_MB_PAD_RIGHT;  break;
    default:
        return false;
    }

    return true;
}
FINLINE bool FInputTransmit_android_key(FINPUT_PACKAGE& ipk, struct android_app* app, AInputEvent* event)
{
    ipk.nType = eIT_UNKNOWN;
    ipk.p1.t = eFDT_unknown;
    ipk.p2.t = eFDT_unknown;

    int32_t key = AKeyEvent_getKeyCode(event);
    int32_t type = AKeyEvent_getAction(event);

    return FInputTransmit_android_key_make(ipk, type, key);
}
#elif FUEL_OS_IOS
#endif
